<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@ include file="/platform/style.jsp" %>
</head>
<style>
    .serch {
        margin: 5px;
        padding: 4px 10px;
        background: #1C84C6;
        border-radius: 5px;
        color: #fff;
        text-decoration: none;
    }

    .Status {
        height: 26px;
        width: 80px;
    }

    .searchinput {
        width: 170px;
        height: 26px !important;
    }

    .bluers {
        color: #00A4F2;
        cursor: pointer;
        text-decoration: none;
    }
</style>
<body class="easyui-layout">
<div data-options="region:'center'" class="bodybg">
    <!-- 查询区域 -->
    <form id="queryForm" action="/couponSet/CouponSetPage.page" method="post">
        <div class="panel">
            <div class="easyui-panel ui-queryBar panel-body panel-body-noheader panel-body-noborder" border="false"
                 data-options="doSize:false" title="">
                <w:hidden bind="pageNum"/>
                <w:hidden bind="pageSize_"/>
                <table cellpadding="0" id="tablepromot" cellspacing="0" style="margin-top:5px">
                    <tbody>
                    <tr>
                        <td width="100" align="right">优惠劵名称：</td>
                        <td><input type="text" class="searchinput" name="bean.name"
                                   value="<w:write bind="bean.name"/>"/></td>
                        <td width="100" align="right">使用平台：</td>
                        <td>
                            <select class="Status" name="bean.platform">
                                <w:option bind="bean.platform" value="">所有</w:option>
                                <w:option bind="bean.platform" value="0">全平台</w:option>
                                <w:option bind="bean.platform" value="1">PC端</w:option>
                                <w:option bind="bean.platform" value="2">微商城</w:option></select>
                            </select>
                        </td>
                        <td width="100" align="right">优惠劵状态：</td>
                        <td>
                        <td>
                            <select class="Status" name="bean.state">
                                <w:option bind="bean.state" value="">所有</w:option>
                                <w:option bind="bean.state" value="0">无效</w:option>
                                <w:option bind="bean.state" value="1">有效</w:option>
                            </select>
                        </td>
                        <td>
                            <a href="javascript:void(0)" class="serch" onclick="query()">查询</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
            <a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="toCouponDetails()">优惠劵列表</a>
            <a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="addCoupon()">创建优惠劵</a>
        </div>
        <div class="ui_line" style="margin-top:10px"></div>
        <!-- 数据列表区域 -->
        <table class="ui-table" width="100%" cellpadding="1" cellspacing="1"
               data-options="showPage:true,pageNum:<w:write bind="pageNum"/>,pageSize:<w:write bind="pageSize_"/>,total:<w:write bind="pagination.totalCount"/>,form:'queryForm'">
            <thead>
            <tr class="ui_th">
                <td>优惠劵编号</td>
                <td>可领取</td>
                <td>使用平台</td>
                <td>优惠劵名称</td>
                <td>有效期</td>
                <td>最小金额</td>
                <td>面额</td>
                <td>使用范围</td>
                <td>已发放</td>
                <td>已使用</td>
                <td>优惠劵状态</td>
                <td width="110" align="center">操作</td>
            </tr>
            </thead>
            <tbody>
            <w:iterate id="info" bind="resultList_">
                <tr class="ui_td">
                    <td><w:write bind="#info.id"/></td>
                    <td><w:write bind="#info.receive" defaultVal="否" format="[否,是]"/></td>
                    <td><w:write bind="#info.source" defaultVal="全平台" format="[全平台,PC端,微信]"/></td>
                    <td><w:write bind="#info.name"/></td>
                    <td><w:write bind="#info.startdate"/>~<w:write bind="#info.enddate"/></td>
                    <td>￥<w:write bind="#info.min_money"/></td>
                    <td>￥<w:write bind="#info.offer_money"/></td>
                    <td><w:write bind="#info.rang"/></td>
                    <td><w:write bind="#info.sales"/></td>
                    <td><w:write bind="#info.usenum"/></td>
                    <td><w:write bind="#info.available" format="[无效,有效]"/></td>
                    <td align="center">
                        <a href="javascript:void(0);" class="ui_btn_2"
                           onclick="SendCoupon(<w:write bind="#info.id"/>);">发送</a>
                        <a href="javascript:void(0);" class="ui_btn marginR8"
                           onclick="EditCoupon(<w:write bind="#info.id"/>);">编辑</a>
                        <a href="javascript:void(0);" class="ui_btn marginR8"
                           onclick="delleteCoupon(<w:write bind="#info.id"/>);">删除</a>
                    </td>
                </tr>
            </w:iterate>
            </tbody>
        </table>
    </form>
</div>
<script>
    function query() {
        $w.execForm({pageNum: 1})
    }
    function toCouponDetails() {
        window.location.href=ctx + '/couponSet/CouponSetPage@details.page';
    }
    function addCoupon() {
        $w.openDialog({
            url: ctx + '/couponSet/CouponSetPage@show.page',
            title: "添加优惠劵",
            w: 700,
            h: 450,
            maximized: true,
            afterClose: function (re) {
                if (re) {
                    query();
                }
            }
        });
    }
    function EditCoupon(id) {
        $w.openDialog({
            url: ctx + '/couponSet/CouponSetPage@show.page?bean.id=' + id,
            title: "编辑优惠劵",
            w: 700,
            h: 450,
            maximized: true,
            afterClose: function (re) {
                if (re) {
                    query();
                }
            }
        });
    }
    function delleteCoupon(id) {
        $.messager.confirm('提示', '</br>是否删除本张优惠劵?</br></br>', function (r) {
            if (r) {
                $w.doUrl(ctx + "/couponSet/CouponSetPage@del.page?bean.id=" + id, null, function (json) {
                    $w.execForm();
                })
            }
        })
    }
    function SendCoupon(id) {
        window.parent.$w.openDialog({
            url: ctx + '/couponSet/CouponSetPage@userselQuery.page',
            title: "选择客户",
            w: 859,
            h: 380,
            afterClose: function (re) {
                if (re && re.length > 0) {
                    var userids = "";
                    for (var i = 0; i < re.length; i++) {
                        if (userids != "") userids += ",";
                        userids += re[i].id;
                    }
                    $w.doUrl(ctx + "/couponSet/CouponSetPage@send.page?bean.id=" + id + "&bean.userids=" + userids, {}, function (ret) {
                        if (ret.state == 'ok') {
                            window.parent.$w.correctMsg("派送成功!");
                            $w.execForm();
                        }
                    })
                }
            }
        });
    }

</script>
</body>
</html>
